﻿using DiyEFConfigurationBuilder.Obersver;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;

namespace DiyEFConfigurationBuilder
{
    internal class EntityChangeObserver
    {
        private EntityChangeObserver() { }

        public event EventHandler<EntityChangeEventArgs> Changed;

        public void OnChanged(EntityChangeEventArgs e)
        {
            ThreadPool.QueueUserWorkItem((_) => Changed?.Invoke(this, e));
        }

        private static readonly Lazy<EntityChangeObserver> lazy = new Lazy<EntityChangeObserver>(() => new EntityChangeObserver());
        
        public static EntityChangeObserver Instance => lazy.Value;
    }
}
